package com.xbongbong.saas.service.impl;

import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.productionorderuser.pojo.dto.ProductionOrderUserDeleteBatchDTO;
import com.xbongbong.pro.productionorderuser.pojo.vo.ProductionOrderUserDeleteBatchVO;
import com.xbongbong.saas.model.ProductionOrderUserModel;
import com.xbongbong.saas.service.ProductionOrderUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * @author 吴峰
 * @version v1.0
 * @date 2019/3/6 20:23
 * @since v1.0
 */
@Service("productionOrderUserService")
public class ProductionOrderUserServiceImpl implements ProductionOrderUserService {

    private static final Logger LOG = LoggerFactory.getLogger(ProductionOrderUserServiceImpl.class);

    @Resource
    private ProductionOrderUserModel productionOrderUserModel;

    @Override
    public ProductionOrderUserDeleteBatchVO deleteBatch(ProductionOrderUserDeleteBatchDTO productionOrderUserDeleteBatchDTO) throws XbbException {
        ProductionOrderUserDeleteBatchVO productionOrderUserDeleteBatchVO = new ProductionOrderUserDeleteBatchVO();
        try {
            List<Long> productOrderIdIn = productionOrderUserDeleteBatchDTO.getProductOrderIdIn();
            String corpid = productionOrderUserDeleteBatchDTO.getCorpid();
            if (Objects.nonNull(productOrderIdIn) && !productOrderIdIn.isEmpty()) {
                productionOrderUserModel.deleteByProOrderIdIn(productOrderIdIn, corpid);
            }
        } catch (Exception e) {
            LOG.error("ProductionOrderUserServiceImpl.deleteBatch 执行出错：", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        return productionOrderUserDeleteBatchVO;
    }
}
